﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.Domain.PermisosModule.Contracts.Areas;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.DistributedServices.Core.ErrorHandlers;
using Cesave.DistributedServices.PermisosModule.Resources;
using System.ServiceModel;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		public void AddArea(Domain.PermisosModule.Entities.Area area)
		{
			try
			{
				IAreaService areaService = IoCFactory.Resolve<IAreaService>();
				areaService.AddArea(area);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		public void ChangeArea(Domain.PermisosModule.Entities.Area area)
		{
			try
			{
				IAreaService areaService = IoCFactory.Resolve<IAreaService>();
				areaService.ChangeArea(area);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		public List<Domain.PermisosModule.Entities.Area> FindAreasByJunta(Guid juntaGuid)
		{
			try
			{
				IAreaService areaService = IoCFactory.Resolve<IAreaService>();
				return areaService.FindAreasByJunta(juntaGuid);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		public void DeleteArea(Domain.PermisosModule.Entities.Area area)
		{
			try
			{
				IAreaService areaService = IoCFactory.Resolve<IAreaService>();
				areaService.DeleteArea(area);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				ServiceError detail = ServiceError.Factory(ex.Message);
				throw new FaultException<ServiceError>(detail);
			}
		}

		#endregion
	}
}
